home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / genmix1b.zip / GENMIX / TST / MIXTEST.C next >
C/C++ Source or Header  |  1995-04-12  |  24KB  |  907 lines

  1. #include "port.h"
  2.  
  3. HINSTANCE globinst;
  4. HWND hwndmain, hwnddlg;
  5.  
  6. waveRate    rate = waveRate22k;
  7. waveBits    bits = waveBits8;
  8. waveSpeak    speak = waveSpeakMono;
  9. int            mixeropen = 0;
  10. int            numchan = 0;
  11. int            numchancur = 0;
  12. int            chanloaded[9];
  13. mixSound    chansound[9];
  14. handle        chanhand[9];
  15. int            chanmute[9];
  16. int            chanloop[9];
  17. DWORD        chanlooptrigms[9];
  18. int            chanlooprate[9];
  19. int            chanvol[9];
  20. int            chanbal[9];
  21.  
  22. static void closemixer(void)
  23. {
  24.     if (!mixeropen) return;
  25.     mixeropen = 0;
  26.     mixClose();
  27. }
  28.  
  29. static void setchannelmixvol(short num, short now);
  30.  
  31. static void openmixer(void)
  32. {
  33.     short    i;
  34.  
  35.     if (mixeropen) closemixer();
  36.     mixOpen((short)numchan,speak,rate,bits);
  37.     mixeropen = 1;
  38.     for (i=0; i<numchan; i++)
  39.           setchannelmixvol(i+(short)1, (short)0);
  40. }
  41.  
  42. static void setrate(waveRate r)
  43. {
  44.     switch (r)
  45.     {
  46.         case waveRate11k: CheckRadioButton(hwnddlg,2,4,2); break;
  47.         case waveRate22k: CheckRadioButton(hwnddlg,2,4,3); break;
  48.         case waveRate44k: CheckRadioButton(hwnddlg,2,4,4); break;
  49.     }
  50.     if (rate != r) {
  51.         closemixer();
  52.         rate = r;
  53.         openmixer();
  54.     }
  55. }
  56.  
  57. static void setbits(waveBits b)
  58. {
  59.     switch (b)
  60.     {
  61.         case waveBits8:  CheckRadioButton(hwnddlg,5,6,5); break;
  62.         case waveBits16: CheckRadioButton(hwnddlg,5,6,6); break;
  63.     }
  64.     if (bits != b) {
  65.         closemixer();
  66.         bits = b;
  67.         openmixer();
  68.     }
  69. }
  70.  
  71. static void setspeak(waveSpeak s)
  72. {
  73.     switch (s)
  74.     {
  75.         case waveSpeakMono:   CheckRadioButton(hwnddlg,7,8,7); break;
  76.         case waveSpeakStereo: CheckRadioButton(hwnddlg,7,8,8); break;
  77.     }
  78.     if (speak != s) {
  79.         closemixer();
  80.         speak = s;
  81.         openmixer();
  82.     }
  83. }
  84.  
  85. typedef struct
  86. {
  87.     long    samplesleft;
  88.     long    samplesize;
  89.     long    blocksize;
  90. } ourcodecData, *pourcodecData;
  91.  
  92. void ourcodecRend(pmem psrc, pmem pdst, pourcodecData ourdata)
  93. {
  94.     long    bytesthis;
  95.  
  96.     bytesthis = ourdata->samplesleft * ourdata->samplesize;
  97.     if (bytesthis > ourdata->blocksize) bytesthis = ourdata->blocksize;
  98.     memCopy(psrc, pdst, bytesthis);
  99.     return;
  100. }
  101.  
  102. void ourcodecInit(pmixSound pms, pourcodecData ourdata)
  103. {
  104.     ourdata->samplesleft = pms->samples;
  105.     ourdata->samplesize = (long)pms->bits * (long)pms->speak;
  106.     ourdata->blocksize = 256;
  107.     return;
  108. }
  109.  
  110. static void installourcodec()
  111. {
  112.     mixCodec mc;
  113.  
  114.     mc.type = mixCodecCyberflix;
  115.     mc.blocksize = 256;
  116.     mc.datasize = 16;
  117.     mc.rendfn = ourcodecRend;
  118.     mc.initfn = ourcodecInit;
  119.     mixInstallCodec(&mc);
  120.     return;
  121. }
  122.  
  123. static short readwavefile(char *szFileName, int chan)
  124. {
  125.     HMMIO           hmmio;
  126.     MMCKINFO        mmckinfoParent;
  127.     MMCKINFO        mmckinfoSubchunk;
  128.     DWORD           dwFmtSize;
  129.     HANDLE          hFormat;
  130.     WAVEFORMAT      *pFormat;
  131.     DWORD           dwDataSize;
  132.     HANDLE          hData       = NULL;
  133.     HPSTR           lpData      = NULL;
  134.     mixSound        ms;
  135.  
  136.     /* Open the given file for reading using buffered I/O.
  137.      */
  138.     if(!(hmmio = mmioOpen(szFileName, NULL, MMIO_READ | MMIO_ALLOCBUF)))
  139.     {
  140.         MessageBox(hwnddlg, "Failed to open file.",
  141.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  142.         return 1;
  143.     }
  144.  
  145.     /* Locate a 'RIFF' chunk with a 'WAVE' form type
  146.      * to make sure it's a WAVE file.
  147.      */
  148.     mmckinfoParent.fccType = mmioFOURCC('W', 'A', 'V', 'E');
  149.     if (mmioDescend(hmmio, (LPMMCKINFO) &mmckinfoParent, NULL, MMIO_FINDRIFF))
  150.     {
  151.         MessageBox(hwnddlg, "This is not a WAVE file.",
  152.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  153.         mmioClose(hmmio, 0);
  154.         return 1;
  155.     }
  156.  
  157.     /* Now, find the format chunk (form type 'fmt '). It should be
  158.      * a subchunk of the 'RIFF' parent chunk.
  159.      */
  160.     mmckinfoSubchunk.ckid = mmioFOURCC('f', 'm', 't', ' ');
  161.     if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent,
  162.         MMIO_FINDCHUNK))
  163.     {
  164.         MessageBox(hwnddlg, "WAVE file is corrupted.",
  165.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  166.         mmioClose(hmmio, 0);
  167.         return 1;
  168.     }
  169.  
  170.     /* Get the size of the format chunk, allocate and lock memory for it.
  171.      */
  172.     dwFmtSize = mmckinfoSubchunk.cksize;
  173.     hFormat = LocalAlloc(LMEM_MOVEABLE, LOWORD(dwFmtSize));
  174.     if (!hFormat)
  175.     {
  176.         MessageBox(hwnddlg, "Out of memory.",
  177.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  178.         mmioClose(hmmio, 0);
  179.         return 1;
  180.     }
  181.     pFormat = (WAVEFORMAT *) LocalLock(hFormat);
  182.     if (!pFormat)
  183.     {
  184.         MessageBox(hwnddlg, "Failed to lock memory for format chunk.",
  185.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  186.         LocalFree( hFormat );
  187.         mmioClose(hmmio, 0);
  188.         return 1;
  189.     }
  190.  
  191.     /* Read the format chunk.
  192.      */
  193.     if (mmioRead(hmmio, (HPSTR) pFormat, dwFmtSize) != (LONG) dwFmtSize)
  194.     {
  195.         MessageBox(hwnddlg, "Failed to read format chunk.",
  196.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  197.         LocalUnlock( hFormat );
  198.         LocalFree( hFormat );
  199.         mmioClose(hmmio, 0);
  200.         return 1;
  201.     }
  202.  
  203.     /* Make sure it's a PCM file.
  204.      */
  205.     if (pFormat->wFormatTag != WAVE_FORMAT_PCM)
  206.     {
  207.         LocalUnlock( hFormat );
  208.         LocalFree( hFormat );
  209.         mmioClose(hmmio, 0);
  210.         MessageBox(hwnddlg, "The file is not a PCM file.",
  211.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  212.         return 1;
  213.     }
  214.  
  215.     /* Ascend out of the format subchunk.
  216.      */
  217.     mmioAscend(hmmio, &mmckinfoSubchunk, 0);
  218.  
  219.     /* Find the data subchunk.
  220.      */
  221.     mmckinfoSubchunk.ckid = mmioFOURCC('d', 'a', 't', 'a');
  222.     if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent,
  223.         MMIO_FINDCHUNK))
  224.     {
  225.         MessageBox(hwnddlg, "WAVE file has no data chunk.",
  226.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  227.         LocalUnlock( hFormat );
  228.         LocalFree( hFormat );
  229.         mmioClose(hmmio, 0);
  230.         return 1;
  231.     }
  232.  
  233.     /* Get the size of the data subchunk.
  234.      */
  235.     dwDataSize = mmckinfoSubchunk.cksize;
  236.     if (dwDataSize == 0L)
  237.     {
  238.         MessageBox(hwnddlg, "The data chunk has no data.",
  239.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  240.         LocalUnlock( hFormat );
  241.         LocalFree( hFormat );
  242.         mmioClose(hmmio, 0);
  243.         return 1;
  244.     }
  245.  
  246.     switch (pFormat->nChannels)
  247.     {
  248.         case 1:
  249.             ms.speak = waveSpeakMono; break;
  250.         case 2:
  251.             ms.speak = waveSpeakStereo; break;
  252.     }                                  
  253.     switch (pFormat->nSamplesPerSec)
  254.     {
  255.         case 11025:
  256.             ms.rate = waveRate11k; break;
  257.         case 22050:
  258.             ms.rate = waveRate22k; break;
  259.         default:
  260.         case 44100:
  261.             ms.rate = waveRate44k; break;
  262.     }
  263.     switch (pFormat->nBlockAlign / pFormat->nChannels)
  264.     {
  265.         case 1:
  266.             ms.bits = waveBits8; break;
  267.         case 2:
  268.             ms.bits = waveBits16; break;
  269.     }
  270.  
  271.     /* We're done with the format header, free it.
  272.      */
  273.     LocalUnlock( hFormat );
  274.     LocalFree( hFormat );
  275.  
  276.     /* Allocate and lock memory for the waveform data.
  277.      */
  278.     hData = GlobalAlloc(GMEM_MOVEABLE , dwDataSize );
  279.                        /* GMEM_SHARE is not needed on 32 bits */
  280.     if (!hData)
  281.     {
  282.         MessageBox(hwnddlg, "Out of memory.",
  283.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  284.         mmioClose(hmmio, 0);
  285.         return 1;
  286.     }
  287.     lpData = GlobalLock(hData);
  288.     if (!lpData)
  289.     {
  290.         MessageBox(hwnddlg, "Failed to lock memory for data chunk.",
  291.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  292.         GlobalFree( hData );
  293.         mmioClose(hmmio, 0);
  294.         return 1;
  295.     }
  296.  
  297.     /* Read the waveform data subchunk.
  298.      */
  299.     if(mmioRead(hmmio, (HPSTR) lpData, dwDataSize) != (LONG) dwDataSize)
  300.     {
  301.         MessageBox(hwnddlg, "Failed to read data chunk.",
  302.                    NULL, MB_OK | MB_ICONEXCLAMATION);
  303.         GlobalUnlock( hData );
  304.         GlobalFree( hData );
  305.         mmioClose(hmmio, 0);
  306.         return 1;
  307.     }
  308.  
  309.     /* We're done with the file, close it.
  310.      */
  311.     mmioClose(hmmio, 0);
  312.  
  313.     chanhand[chan] = hData;
  314.     ms.pdata = lpData;
  315.     ms.samples = dwDataSize / (long) (ms.bits*ms.speak);
  316.     ms.type = mixCodecPCM;
  317.     mixVolCreate(&ms.vol, 1.0, 1.0);
  318.     chansound[chan] = ms;
  319.     chanloaded[chan] = 1;
  320.     return 0;
  321. }
  322.  
  323. static void disablechannel(short num);
  324. static void enablechannel(short num);
  325.  
  326. static void unloadchan(short num)
  327. {
  328.     if (!chanloaded[num]) return;
  329.     chanloaded[num] = 0;
  330.     mixUnplay(chansound[num].pdata);
  331.     GlobalUnlock(chanhand[num]);
  332.     GlobalFree(chanhand[num]);
  333.     enablechannel(num);
  334. }
  335.  
  336. static void setchannelmixvol(short num, short now)
  337. {
  338.     float    l,r;
  339.     float    t,b;
  340.     mixVol    mv;
  341.  
  342.     t = (float)chanvol[num] / (float)2048.0;
  343.     b = (float)chanbal[num] / (float)4096.0;
  344.     r = b * t;
  345.     l = ((float)1.0 - b) * t;
  346.     mixVolCreate(&mv, l*2.0,r*2.0);
  347.     mixSetVolume((short)num-(short)1, &mv);
  348.     return;
  349. }
  350.  
  351. static void loadchan(short num)
  352. {
  353.     int err;
  354.     OPENFILENAME ofn;
  355.     unsigned char tempstring[256], charstring[256], thename[256];
  356.     
  357.     strcpy(tempstring, "");
  358.     charstring[0] = 0;
  359.     thename[0] = 0;
  360.     memset(&ofn, 0, sizeof(OPENFILENAME));
  361.     ofn.lStructSize = sizeof(OPENFILENAME);
  362.     ofn.hwndOwner = hwnddlg;
  363.     ofn.lpstrFilter = "Wave files (.WAV)\0*.wav\0\0";
  364.     ofn.nFilterIndex = 1;
  365.     ofn.lpstrDefExt = "WAV";
  366.     ofn.lpstrFile = thename;
  367.     ofn.nMaxFile = 256;
  368.     ofn.lpstrFileTitle = charstring;
  369.     ofn.nMaxFileTitle = 256;
  370.     ofn.lpstrInitialDir = tempstring;
  371.     ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  372.     err = GetOpenFileName(&ofn);
  373.     if (!err) return;
  374.     if (chanloaded[num]) unloadchan(num);
  375.     err = readwavefile(thename, num);
  376.     if (err) return;
  377.     strupr(charstring);
  378.     SetDlgItemText(hwnddlg, num*100+1, charstring);
  379.     strcpy(tempstring, "");
  380.     switch (chansound[num].rate)
  381.     {
  382.         case waveRate11k:  strcat(tempstring, "11kHz"); break;
  383.         case waveRate22k:  strcat(tempstring, "22kHz"); break;
  384.         case waveRate44k:  strcat(tempstring, "44kHz"); break;
  385.     }
  386.     switch (chansound[num].bits)
  387.     {
  388.         case waveBits8:        strcat(tempstring, " 8 bit"); break;
  389.         case waveBits16:    strcat(tempstring, " 16 bit"); break;
  390.     }
  391.     switch (chansound[num].speak)
  392.     {
  393.         case waveSpeakMono:    strcat(tempstring, " mono"); break;
  394.         case waveSpeakStereo: strcat(tempstring, " stereo"); break;
  395.     }
  396.     SetDlgItemText(hwnddlg, num*100+2, tempstring);
  397.     CheckDlgButton(hwnddlg, num*100+3, FALSE);
  398.     EnableWindow(GetDlgItem(hwnddlg,num*100+3), TRUE);
  399.     chanloop[num] = 0;
  400.     CheckDlgButton(hwnddlg, num*100+4, FALSE);
  401.     EnableWindow(GetDlgItem(hwnddlg,num*100+4), TRUE);
  402.     chanmute[num] = 0;
  403.  
  404.     SetScrollRange(GetDlgItem(hwnddlg,num*100+5), SB_CTL, 100,5000, FALSE);
  405.     SetScrollPos(GetDlgItem(hwnddlg,num*100+5), SB_CTL, 1000, TRUE);
  406.     EnableWindow(GetDlgItem(hwnddlg,num*100+5), TRUE);
  407.     chanlooprate[num] = 1000;
  408.  
  409.     SetScrollRange(GetDlgItem(hwnddlg,num*100+6), SB_CTL, 0,4096, FALSE);
  410.     SetScrollPos(GetDlgItem(hwnddlg,num*100+6), SB_CTL, 2048, TRUE);
  411.     EnableWindow(GetDlgItem(hwnddlg,num*100+6), TRUE);
  412.     chanvol[num] = 2048;
  413.  
  414.     SetScrollRange(GetDlgItem(hwnddlg,num*100+7), SB_CTL, 0,4096, FALSE);
  415.     SetScrollPos(GetDlgItem(hwnddlg,num*100+7), SB_CTL, 2048, TRUE);
  416.     EnableWindow(GetDlgItem(hwnddlg,num*100+7), TRUE);
  417.     chanbal[num] = 2048;
  418.  
  419.     EnableWindow(GetDlgItem(hwnddlg,num*100+8), TRUE);
  420.     EnableWindow(GetDlgItem(hwnddlg,num*100+9), TRUE);
  421.     setchannelmixvol(num, 0);
  422.  }
  423.  
  424. static void enablechannel(short num)
  425. {
  426.     SetDlgItemText(hwnddlg,num*100+1, "[NONE]");
  427.     SetDlgItemText(hwnddlg,num*100+2, "");
  428.     
  429.     CheckDlgButton(hwnddlg, num*100+3, FALSE);
  430.     EnableWindow(GetDlgItem(hwnddlg,num*100+3), FALSE);
  431.     CheckDlgButton(hwnddlg, num*100+4, FALSE);
  432.     EnableWindow(GetDlgItem(hwnddlg,num*100+4), FALSE);
  433.  
  434.     SetScrollRange(GetDlgItem(hwnddlg,num*100+5), SB_CTL, 0,0, TRUE);
  435.     EnableWindow(GetDlgItem(hwnddlg,num*100+5), FALSE);
  436.     SetScrollRange(GetDlgItem(hwnddlg,num*100+6), SB_CTL, 0,0, TRUE);
  437.     EnableWindow(GetDlgItem(hwnddlg,num*100+6), FALSE);
  438.     SetScrollRange(GetDlgItem(hwnddlg,num*100+7), SB_CTL, 0,0, TRUE);
  439.     EnableWindow(GetDlgItem(hwnddlg,num*100+7), FALSE);
  440.  
  441.     EnableWindow(GetDlgItem(hwnddlg,num*100+8), TRUE);
  442.     EnableWindow(GetDlgItem(hwnddlg,num*100+9), FALSE);
  443. }
  444.  
  445. static void disablechannel(short num)
  446. {
  447.     SetDlgItemText(hwnddlg,num*100+1, "[UNUSED]");
  448.     SetDlgItemText(hwnddlg,num*100+2, "");
  449.     
  450.     CheckDlgButton(hwnddlg, num*100+3, FALSE);
  451.     EnableWindow(GetDlgItem(hwnddlg,num*100+3), FALSE);
  452.     CheckDlgButton(hwnddlg, num*100+4, FALSE);
  453.     EnableWindow(GetDlgItem(hwnddlg,num*100+4), FALSE);
  454.  
  455.     SetScrollRange(GetDlgItem(hwnddlg,num*100+5), SB_CTL, 0,0, FALSE);
  456.     EnableWindow(GetDlgItem(hwnddlg,num*100+5), FALSE);
  457.     SetScrollRange(GetDlgItem(hwnddlg,num*100+6), SB_CTL, 0,0, FALSE);
  458.     EnableWindow(GetDlgItem(hwnddlg,num*100+6), FALSE);
  459.     SetScrollRange(GetDlgItem(hwnddlg,num*100+7), SB_CTL, 0,0, FALSE);
  460.     EnableWindow(GetDlgItem(hwnddlg,num*100+7), FALSE);
  461.  
  462.     EnableWindow(GetDlgItem(hwnddlg,num*100+8), FALSE);
  463.     EnableWindow(GetDlgItem(hwnddlg,num*100+9), FALSE);
  464.     chanloop[num] = 0;
  465.     if (chanloaded[num]) unloadchan(num);
  466. }
  467.  
  468. static void setnumchan(short num)
  469. {
  470.     short    i;
  471.  
  472.     SetScrollRange(GetDlgItem(hwnddlg,10), SB_CTL, 1,8, FALSE);
  473.     SetScrollPos(GetDlgItem(hwnddlg,10), SB_CTL, num, FALSE);
  474.     SetDlgItemInt(hwnddlg,9,num,TRUE);
  475.     for (i=numchancur; i<num; i++)
  476.         enablechannel((short)i+(short)1);
  477.     for (i=num; i<8; i++)
  478.         disablechannel((short)i+(short)1);
  479.     numchancur = num;
  480.     closemixer();
  481.     numchan = num;
  482.     openmixer();
  483. }
  484.  
  485. static void chanreloop(short chan)
  486. {
  487.     if (chanloop[chan])
  488.     {
  489.         chanlooptrigms[chan] = 0;
  490.     }
  491.     chanloop[chan] = IsDlgButtonChecked(hwnddlg, 100*chan + 4);
  492.     if (chanloop[chan])
  493.     {
  494.         chanlooptrigms[chan] = timeGetTime() + chanlooprate[chan];
  495.     }
  496.     return;
  497. }
  498.  
  499. static void checkevents()
  500. {
  501.     short    i;
  502.     DWORD    t;
  503.  
  504.     if (!mixeropen) return;
  505.     t = timeGetTime();
  506.     for (i=1; i<=numchan; i++)
  507.         if (chanloop[i] && chanlooptrigms[i] && t>=chanlooptrigms[i])
  508.         {
  509.             mixPlay(i-(short)1, chansound+i);
  510.             chanlooptrigms[i] = t + chanlooprate[i];
  511.         }
  512.     mixPump();
  513.     return;
  514. }
  515.  
  516. static void dialoginit(void)
  517. {
  518.     RECT    rdlg;
  519.     int        w,h,i;
  520.  
  521.     ShowWindow(hwnddlg, SW_SHOW);
  522.     ShowWindow(hwndmain, SW_SHOW);
  523.     GetWindowRect(hwnddlg, &rdlg);
  524.     AdjustWindowRectEx(&rdlg, WS_TILEDWINDOW, FALSE, 0);
  525.     w = rdlg.right - rdlg.left;
  526.     h = rdlg.bottom -rdlg.top;
  527.     SetWindowPos(hwndmain, HWND_TOP, 0,0,w,h, SWP_NOMOVE|SWP_SHOWWINDOW);
  528.     for (i=0; i<8; i++)
  529.         chanloaded[i] = 0;
  530.     setnumchan(4);
  531.     setrate(waveRate22k);
  532.     setbits(waveBits8);
  533.     setspeak(waveSpeakMono);
  534.     return;    
  535. }
  536.  
  537. int handlescroll(WPARAM wp, LPARAM lp, int *pos, int mn, int mx)
  538. {
  539.     int nScrollCode = (int) LOWORD(wp);  // scroll bar value     
  540.     short nPos = (short int) HIWORD(wp);   // scroll box position  
  541.     HWND hwndScrollBar = (HWND) lp;       // handle of scroll bar
  542.     int    x;
  543.       
  544.     switch (nScrollCode)
  545.     {
  546.         case SB_BOTTOM:        x = mx; break;
  547.         case SB_ENDSCROLL:    x = *pos; break;
  548.         case SB_LINELEFT:    x = *pos - 1; break;
  549.         case SB_LINERIGHT:    x = *pos + 1; break;
  550.         case SB_PAGELEFT:    x = *pos - 1; break;
  551.         case SB_PAGERIGHT:    x = *pos + 1; break;
  552.         case SB_THUMBPOSITION:    x = nPos; break;
  553.         case SB_THUMBTRACK:    x = *pos; break;
  554.         case SB_TOP:        x = mn; break;
  555.     }
  556.     if (x<mn) x = mn;
  557.     if (x>mx) x = mx;
  558.     if (x == *pos) return 0;
  559.     *pos = x;
  560.     SetScrollPos(hwndScrollBar, SB_CTL, x, TRUE);
  561.     return 1;
  562. }
  563.  
  564. int    bsiz, bahead, ppos, pmix, cformat;
  565. HWND hwndhw;
  566. char *formatstr;
  567.  
  568. void updateradio()
  569. {
  570.     switch (((rate-1)<<2) | ((bits-1)<<1) | (speak-1))
  571.     {
  572.         case 0: CheckRadioButton(hwndhw,51,62,51); break;
  573.         case 1: CheckRadioButton(hwndhw,51,62,52); break;
  574.         case 2: CheckRadioButton(hwndhw,51,62,53); break;
  575.         case 3: CheckRadioButton(hwndhw,51,62,54); break;
  576.         case 4: CheckRadioButton(hwndhw,51,62,55); break;
  577.         case 5: CheckRadioButton(hwndhw,51,62,56); break;
  578.         case 6: CheckRadioButton(hwndhw,51,62,57); break;
  579.         case 7: CheckRadioButton(hwndhw,51,62,58); break;
  580.         case 12: CheckRadioButton(hwndhw,51,62,59); break;
  581.         case 13: CheckRadioButton(hwndhw,51,62,60); break;
  582.         case 14: CheckRadioButton(hwndhw,51,62,61); break;
  583.         case 15: CheckRadioButton(hwndhw,51,62,62); break;
  584.     }
  585.     switch (bsiz)
  586.     {
  587.         case 512: CheckRadioButton(hwndhw,21,26,21); break;
  588.         case 1024: CheckRadioButton(hwndhw,21,26,22); break;
  589.         case 2048: CheckRadioButton(hwndhw,21,26,23); break;
  590.         case 4096: CheckRadioButton(hwndhw,21,26,24); break;
  591.         case 8192: CheckRadioButton(hwndhw,21,26,25); break;
  592.         case 16384: CheckRadioButton(hwndhw,21,26,26); break;
  593.     }
  594.     switch (bahead)
  595.     {
  596.         case 1: CheckRadioButton(hwndhw, 11,18,11); break;
  597.         case 2: CheckRadioButton(hwndhw, 11,18,12); break;
  598.         case 3: CheckRadioButton(hwndhw, 11,18,13); break;
  599.         case 4: CheckRadioButton(hwndhw, 11,18,14); break;
  600.         case 5: CheckRadioButton(hwndhw, 11,18,15); break;
  601.         case 6: CheckRadioButton(hwndhw, 11,18,16); break;
  602.         case 7: CheckRadioButton(hwndhw, 11,18,17); break;
  603.         case 8: CheckRadioButton(hwndhw, 11,18,18); break;
  604.     }
  605.     if (pmix) CheckRadioButton(hwndhw, 31,32,31);
  606.     else CheckRadioButton(hwndhw, 31,32,32);
  607.     if (ppos) CheckRadioButton(hwndhw, 41,42,41);
  608.     else CheckRadioButton(hwndhw, 41,42,42);
  609.     return;
  610. }
  611.  
  612. #define inifile        "portwave.ini"
  613. #define bakfile        "portwave.bak"
  614. extern char    drivername[32];
  615. extern UINT outdev;
  616.  
  617. void getcurhw()
  618. {
  619.     char    formatstr[32];
  620.     char    datastr[32];
  621.     char    verstr[32];
  622.     WAVEOUTCAPS        woc;
  623.  
  624.     sprintf(formatstr, "%dbit%dkhz%s", bits==waveBits8 ? 8 :16,
  625.             11 * (int)rate, speak==waveSpeakMono ? "mono" : "stereo");
  626.     GetPrivateProfileString(drivername, formatstr, "", datastr,
  627.             sizeof(datastr), inifile); 
  628.     if (4 != sscanf(datastr, "%d %d %d %d", &bsiz, &bahead, 
  629.         &pmix, &ppos))
  630.     {
  631.         GetPrivateProfileString("default", formatstr, "", datastr,
  632.                 sizeof(datastr), inifile); 
  633.         if (4 != sscanf(datastr, "%d %d %d %d", &bsiz, &bahead, 
  634.             &pmix, &ppos)) portFatalError(badlog, 0);
  635.         waveOutGetDevCaps(outdev, &woc, sizeof(WAVEOUTCAPS));
  636.         WritePrivateProfileString(drivername, "name", woc.szPname, inifile);
  637.         sprintf(verstr, "%d.%d", (int)HIBYTE(woc.vDriverVersion), 
  638.             (int)LOBYTE(woc.vDriverVersion));
  639.         WritePrivateProfileString(drivername, "version", verstr, inifile);
  640.         WritePrivateProfileString(drivername, "whatversion", "thishilo", inifile);
  641.         WritePrivateProfileString(drivername, formatstr, datastr, inifile);
  642.     }
  643.     updateradio();
  644. }
  645.  
  646. void setcurhw()
  647. {
  648.     char    formatstr[32];
  649.     char    datastr[32];
  650.     char    windir[128], bakfil[128];
  651.  
  652.     GetWindowsDirectory(windir, 128);
  653.     strcpy(bakfil, windir);
  654.     strcat(windir, "\\" inifile);
  655.     strcat(bakfil, "\\" bakfile);    
  656.     CopyFile(windir, bakfil, FALSE);
  657.     sprintf(formatstr, "%dbit%dkhz%s", bits==waveBits8 ? 8 :16,
  658.             11 * (int)rate, speak==waveSpeakMono ? "mono" : "stereo");
  659.     sprintf(datastr, "%d %d %d %d", bsiz, bahead, pmix, ppos);
  660.     WritePrivateProfileString(drivername, formatstr, datastr, inifile);
  661.     updateradio();
  662. }
  663.  
  664. void copycurhw()
  665. {
  666. }
  667.  
  668.  
  669. BOOL CALLBACK hwdlgproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
  670. {
  671.     WORD    ncod;
  672.     WORD    id;
  673.     HWND    hctl;
  674.  
  675.     switch (msg)
  676.     {
  677.         case WM_INITDIALOG:
  678.             hwndhw = hwnd;
  679.             getcurhw();
  680.             return TRUE;
  681.         case WM_COMMAND:
  682.             ncod = HIWORD(wp);
  683.             id = LOWORD(wp);
  684.             hctl = (HWND) lp;
  685.             switch (ncod)
  686.             {
  687.                 case BN_CLICKED:      
  688.                     switch (id/10)
  689.                     {
  690.                         case 1: bahead = id%10; setcurhw(); break;
  691.                         case 2: bsiz = (1<<(id%10))*256; setcurhw(); break;
  692.                         case 3: pmix = (id%10)==1; setcurhw(); break;
  693.                         case 4: ppos = (id%10)==1; setcurhw(); break;
  694.                         case 5:
  695.                         case 6: 
  696.                             switch (id-50)
  697.                             {
  698.                                 case 1: rate=waveRate11k; bits=waveBits8;
  699.                                         speak=waveSpeakMono; break;
  700.                                 case 2: rate=waveRate11k; bits=waveBits8;
  701.                                         speak=waveSpeakStereo; break;
  702.                                 case 3: rate=waveRate11k; bits=waveBits16;
  703.                                         speak=waveSpeakMono; break;
  704.                                 case 4: rate=waveRate11k; bits=waveBits16;
  705.                                         speak=waveSpeakStereo; break;
  706.                                 case 5: rate=waveRate22k; bits=waveBits8;
  707.                                         speak=waveSpeakMono; break;
  708.                                 case 6: rate=waveRate22k; bits=waveBits8;
  709.                                         speak=waveSpeakStereo; break;
  710.                                 case 7: rate=waveRate22k; bits=waveBits16;
  711.                                         speak=waveSpeakMono; break;
  712.                                 case 8: rate=waveRate22k; bits=waveBits16;
  713.                                         speak=waveSpeakStereo; break;
  714.                                 case 9: rate=waveRate44k; bits=waveBits8;
  715.                                         speak=waveSpeakMono; break;
  716.                                 case 10:rate=waveRate44k; bits=waveBits8;
  717.                                         speak=waveSpeakStereo; break;
  718.                                 case 11:rate=waveRate44k; bits=waveBits16;
  719.                                         speak=waveSpeakMono; break;
  720.                                 case 12:rate=waveRate44k; bits=waveBits16;
  721.                                         speak=waveSpeakStereo; break;
  722.                             }
  723.                             getcurhw();
  724.                             break;
  725.                         case 7: copycurhw(); break;
  726.                         case 0:    
  727.                             EndDialog(hwnd, 0);
  728.                             break;
  729.                     }
  730.                     break;
  731.             
  732.             }
  733.             return TRUE;
  734.         default:
  735.             return FALSE;
  736.     }
  737.     return TRUE;
  738. }
  739.  
  740. BOOL CALLBACK dialogfn(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
  741. {
  742.     WORD    ncod;
  743.     WORD    id;
  744.     HWND    hctl;
  745.     short    chan;
  746.  
  747.     switch (msg)
  748.     {
  749.         case WM_INITDIALOG:
  750.             hwnddlg = hwnd;
  751.             dialoginit();
  752.             return TRUE;
  753.         case WM_HSCROLL:
  754.         {
  755.             int id = GetDlgCtrlID((HWND)lp);
  756.             int chan;
  757.  
  758.             chan = id / 100;
  759.             id = id % 100;
  760.             if (chan==0)
  761.             {
  762.                 if (handlescroll(wp,lp, &numchan, 1,8))
  763.                      setnumchan(numchan);
  764.             }
  765.             else switch (id)
  766.             {
  767.                 case 5:
  768.                     if (handlescroll(wp,lp, &chanlooprate[chan], 50,5000))
  769.                          chanreloop(chan);
  770.                     break;
  771.                 case 6:
  772.                     if (handlescroll(wp,lp, &chanvol[chan], 0,4096))
  773.                          setchannelmixvol(chan, 0);
  774.                     break;
  775.                 case 7:
  776.                     if (handlescroll(wp,lp, &chanbal[chan], 0,4096))
  777.                          setchannelmixvol(chan, 0);
  778.                     break;
  779.             }
  780.             return TRUE;
  781.         }
  782.         case WM_COMMAND:
  783.             ncod = HIWORD(wp);
  784.             id = LOWORD(wp);
  785.             hctl = (HWND) lp;
  786.             chan = id / 100;
  787.             id = id % 100;
  788.             if (chan==0)
  789.                 switch (ncod)
  790.                 {
  791.                     case BN_CLICKED:
  792.                         switch (id)
  793.                         {
  794.                             case 1:
  795.                                 EndDialog(hwnd, 0);
  796.                                 PostQuitMessage(0);
  797.                                 break;
  798.                             case 2:
  799.                                 setrate(waveRate11k); break;
  800.                             case 3:
  801.                                 setrate(waveRate22k); break;
  802.                             case 4:
  803.                                 setrate(waveRate44k); break;
  804.                             case 5:
  805.                                 setbits(waveBits8); break;
  806.                             case 6:
  807.                                 setbits(waveBits16); break;
  808.                             case 7:
  809.                                 setspeak(waveSpeakMono); break;
  810.                             case 8:
  811.                                 setspeak(waveSpeakStereo); break;
  812.                             case 11:
  813.                                 closemixer();
  814.                                 DialogBox(globinst, MAKEINTRESOURCE(2), hwnd, hwdlgproc);
  815.                                 setrate(rate);
  816.                                 setbits(bits);
  817.                                 setspeak(speak);
  818.                                 openmixer();
  819.                                 break;  
  820.                         }
  821.                         break;
  822.                 
  823.                 }
  824.             else
  825.                 switch (ncod)
  826.                 {
  827.                     case BN_CLICKED:
  828.                         switch (id)
  829.                         {
  830.                             case 3:
  831.                                 break;
  832.                             case 4:
  833.                                 chanreloop(chan);
  834.                                 break;
  835.                             case 8:
  836.                                 loadchan(chan);        
  837.                                 break;
  838.                             case 9:
  839.                                 mixPlay(chan-1, chansound + chan);
  840.                                 break;
  841.                         }
  842.                 }
  843.             return TRUE;
  844.         default:
  845.             return FALSE;
  846.     }
  847.     return TRUE;
  848. }
  849.  
  850. LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
  851. {
  852.     switch (msg)
  853.     {
  854.         case WM_DESTROY:
  855.             closemixer();
  856.             return 0;
  857. //        case WM_TIMER:
  858. //            checkevents();
  859. //            break;
  860.         case WM_CREATE:
  861.             return 0;
  862.         default:
  863.             return DefWindowProc(hwnd, msg, wp, lp);
  864.     }
  865.     return 0;
  866. }
  867.  
  868.  
  869. int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstprev, LPSTR cmdline, int cshow)
  870. {
  871.     WNDCLASS    wc;
  872.     MSG            msg;
  873.  
  874.     globinst = hinst;
  875.  
  876.     wc.style = CS_PARENTDC;
  877.     wc.lpfnWndProc = wndproc;
  878.     wc.cbClsExtra = 0;
  879.     wc.cbWndExtra = 0;
  880.     wc.hInstance = hinst;
  881.     wc.hIcon = LoadIcon(0,IDI_APPLICATION);
  882.     wc.hCursor = LoadCursor(0,IDC_ARROW);
  883.     wc.hbrBackground = GetStockObject(GRAY_BRUSH);
  884.     wc.lpszMenuName = 0;
  885.     wc.lpszClassName = "MIXTEST";
  886.  
  887.     RegisterClass(&wc);
  888.     hwndmain = CreateWindow("MIXTEST", "Mixer Test", WS_TILEDWINDOW, 
  889.         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
  890.         0, 0, hinst, 0);
  891.     ShowWindow(hwndmain, SW_SHOW);
  892.     CreateDialog(globinst, MAKEINTRESOURCE(1), hwndmain, dialogfn);
  893.  
  894.     while (1) 
  895.     {
  896.         if (PeekMessage(&msg, NULL, 0,0, PM_REMOVE))
  897.         {
  898.             if (msg.message == WM_QUIT) break;
  899.                TranslateMessage(&msg);
  900.             DispatchMessage(&msg); 
  901.         }
  902.         checkevents();
  903.     }
  904.  
  905.     return 0;
  906. }
  907.